<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table>
    <thead>
    <input type="checkbox" name="" id="button_all"> 全选/全不选
    </thead>
    <tbody>
    <tr>
        <td><input type="checkbox"></td>
        <td>aaa</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>bbb</td>
    </tr>
    </tbody>
</table>
<script>
    //1.获取元素
    var button_all = document.getElementById('button_all')
    var button_son = document.querySelector('tbody').getElementsByTagName('input')
<!--    console.log(button_all)-->
<!--    console.log(button_son)-->

    //2.注册事件
    button_all.onclick = function(){
        for (var i=0;i<button_son.length;i++){
            button_son[i].checked = this.checked
        }
    }

    //给每个小按钮绑定一个点击事件
    for (var i=0;i<button_son.length;i++){
        button_son[i].onclick = function(){
            var flag = true
            for (var j = 0;j<button_son.length;j++){
                if(!button_son[j].checked){
                    flag = false
                }
                button_all.checked = flag
            }
        }
    }
</script>
</body>

</html>